<script type="text/javascript">
    $(function() {
        $.fn.dataGridOptions.formSubFun("#form",'/modules/user/score/goods/doAppend.html');
    });
</script>
<form id="form" method="post" enctype="multipart/form-data">
<div class="popShow" style="padding-bottom:0;">
    	<div class="showItem">
    		<span>商品类别：</span>
    		<select name="categoryId" style="width:163px">
				<#list goodsCategoryList as item>
					<option value="${item.id}">${item.name}</option>
				</#list>
			</select>
    	</div>
    	<div class="showItem">
    		<span>商品名称：</span>
    		<input type="text" id="goodsName" name="name" maxlength="120" class="easyui-validatebox" data-options="required: true" />
    	</div>
    	<div class="showItem">
    		<span>所需积分：</span>
    		<input type="text" name="score" maxlength="10" class="easyui-validatebox itemTxt" data-options="required: true,validType:'numOnly'" onKeyUp="value=value.replace(/[^0-9]/g,'')" /><em>分</em>
    	</div>
    	<div class="showItem">
    		<span>市场价：</span>
    		<input type="text" name="marketPrice" maxlength="8" onKeyUp="value=value.replace(/[^0-9]/g,'')" class="easyui-validatebox itemTxt" data-options="required: true, validType:'price'"/><em>元</em>
    	</div>
    	<div class="showItem">
    		<span>商品库存：</span>
    		 <input type="text" name="store" maxlength="5" class="easyui-numberbox itemTxt" data-options="required: true,validType:'numOnly'" onKeyUp="value=value.replace(/[^0-9]/g,'')"/><em>件</em>
    		 <input type="hidden" name="addGoods" value="${addGoods!}"/>
    	</div>
    	<div class="showItem">
    		<span>虚拟商品：</span>
    		<label><input type="radio" name="isVirtual" value="1" />&nbsp;是</label>&nbsp;&nbsp;
			<label><input type="radio" name="isVirtual" value="0" checked="checked"/>&nbsp;否</label>
    	</div>
</div>
<!-- <form method="get" id="uploadForm" action="uploadFile.json" style="display: none;">
    <input type='file' name='uploadFile' id='uploadFile' />
</form> -->
<div class="popForm" style="padding-top:0;">
	<div class="formitm">
		<label class="lab" style="width:130px;">封面图片：</label>
		<div class="ipt">
			<input type="file" name="file">
			<span style="color:#EB4343; display: block;">* 请添加且只能添加一张图片（新上传图片会替换原始图片）</span>
		</div>
	</div>
	<div class="formitm">
		<label style="width:130px;" class="lab">商品详情：</label>
		<div style="margin-left:140px;color:#000;border:1px solid #dedede;" class="ipt">
			<textarea id="description" name="description"  style="height:100px;"></textarea>
		</div>
	</div>
	<div class="formitm">
		<label style="width:130px;" class="lab">商品属性信息：</label>
		<div style="margin-left:140px;color:#000;border:1px solid #dedede;" class="ipt">
			<textarea id="attribute" name="attribute"  style="height:100px;"></textarea>
		</div>
	</div>
	<div class="formitm">
		<label style="width:130px;" class="lab">备注：</label>
		<div style="margin-left:140px;" class="ipt">
			<textarea name="remark" style="width:500px;" class="easyui-validatebox" maxlength="256"></textarea>
		</div>
	</div>
</div>
</form>
<!-- 编辑器 -->
<script type="text/javascript" src="/plugins/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="/plugins/uploadify/jquery.uploadify.js"></script>
<link rel="stylesheet" href="/plugins/uploadify/uploadify.css" type="text/css">
<script type="text/javascript">

	$(".l-btn-text").click(function(){
		if($("input[name='file']").val()==""){
			alert("请上传封面图片");
			return false;
		}

	})
	var image_server_url = $("#image_server_url").val();
    // 编辑器调用
    var tinymceEditor;
    tinymce.init({
        mode : "textareas",
        theme : "modern",//定义显示类别
        language:'zh_CN',//设置语言
        plugins: "fullscreen code preview textcolor",
        theme_advanced_toolbar_location : "top",//定义工具栏的位置
        theme_advanced_toolbar_align : "left", //定义工具栏工具的对其方式
        selector: "#description",
        theme_advanced_statusbar_location : "bottom",//定义输入框下方是否显示状态栏，默认不显示
        theme_advanced_resizing : true,//定义是否可以改变输入窗口大小
        menubar: false,//菜单栏
        toolbar:"fullscreen code styleselect removeformat bold italic alignleft aligncenter alignright fontsizeselect forecolor backcolor imageButton",
        theme_advanced_toolbar_location : "top",//定义工具栏的位置
        theme_advanced_toolbar_align : "left",//定义工具栏工具的对其方式
        toolbar_items_size: 'small',//工具栏图标大小
        setup: function (editor) {
            tinymceEditor = editor;
            editor.addButton('imageButton', {
                icon: 'image',
                onclick: function () {
                	var imgUrl;
                	$.layer({
        			    type: 1,
        			    closeBtn: [0, true],
        			    title: '选择图片',
        			    area: ['550px', '450px'],
        			    border: [0],
        			    page : {
        			    	html:'<div class="uploaderBox"><div class="uploadList"><ul class="filelist"></ul></div><div class="statusBar"><span class="okBtn">确定</span><span><em id="files" name="file"></em></span></div></div>'
        			    }
        			});
                	//图片上传插件
               		$('#files').uploadify({
       	              fileObjName : 'upload',
       	              buttonClass:'uploadBtn',
       	              buttonText:'选择&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
       	              fileTypeDesc:'Image Files',
       	              fileTypeExts:'*.gif; *.jpg; *.png',
       	              fileSizeLimit:'500',
       	           	  width:80,
       	              height:32,
       	              swf:'/plugins/uploadify/uploadify.swf',
       	              uploader:image_server_url+"/upload/uploadifySave.html?nid=goods",
       	              onSelectError: function(file,errorCode,errorMsg){
       	                    if(errorCode==-110){
       	                    	layer.msg('上传的单张图片不能超过500K，请重新上传', 1, -1);
       	                    	return false;
       	                    }
       	                    else if(errorCode==-130){
       	                    	layer.msg('选择的文件类型跟设置的不匹配', 2, -1);
       	                    	return false;
       	                    }
       	              },
       	              onUploadSuccess:function(file,data, response) {
       	            	if(data!=null){
       	                	imgUrl = image_server_url+data;
       	                    $('.filelist').append("<li><a href='"+imgUrl+"' class='fileshow'><img src='"+imgUrl+"' width='110px' height='110px' /></a><i class='iconfont delImgUrl' title='点击删除图片'>&#xe628;</i></li>");
       	                }
       	              }
       	        	});
               		//确定并添加到编辑器
               		$(".okBtn").click(function(){
               			var img = "";
               			$(".filelist li a").each(function(){
               				img += $(this).html();
               			});
               			if(img != "" ){
               				//var img = '<img src="'+imgUrl+'" alt="">';
                            tinymceEditor.insertContent(img);
               			}
               			layer.closeAll();
               		})   
               		//删除图片
					  $(".delImgUrl").live("click",function(){
					    var _that = $(this);
					     $.ajax({
					       url : "/modules/user/score/goods/delPic.html?randomTime=" + (new Date()).getTime(),
					       dataType:'json',
					       data : {pathPic : $(this).prev().attr("src")},
					       success:function(data){
					          if(data.result){
					            _that.parents("li").remove();
					          }
					       }
					     })
					  })
                }
            });
        }, 
        statusbar  : false //控制底部状态栏是否显示
    });
	
    var tinymceEditor1;
    tinymce.init({
        mode : "textareas",
        theme : "modern",//定义显示类别
        language:'zh_CN',//设置语言
        plugins: "fullscreen code textcolor image",
        theme_advanced_toolbar_location : "top",//定义工具栏的位置
        theme_advanced_toolbar_align : "left", //定义工具栏工具的对其方式
        selector: "#attribute",
        theme_advanced_statusbar_location : "bottom",//定义输入框下方是否显示状态栏，默认不显示
        theme_advanced_resizing : true,//定义是否可以改变输入窗口大小
        menubar: false,//菜单栏
        toolbar:"fullscreen code styleselect removeformat bold italic alignleft aligncenter alignright fontsizeselect forecolor backcolor imageButton",
        theme_advanced_toolbar_location : "top",//定义工具栏的位置
        theme_advanced_toolbar_align : "left",//定义工具栏工具的对其方式
        toolbar_items_size: 'small',//工具栏图标大小
        setup: function (editor) {
            tinymceEditor1 = editor;
            editor.addButton('imageButton', {
                icon: 'image',
                onclick: function () {
                	var imgUrl;
                	$.layer({
        			    type: 1,
        			    closeBtn: [0, true],
        			    title: '选择图片',
        			    area: ['550px', '450px'],
        			    border: [0],
        			    page : {
        			    	html:'<div class="uploaderBox"><div class="uploadList"><ul class="filelist"></ul></div><div class="statusBar"><span class="okBtn">确定</span><span><em id="files1" name="file1"></em></span></div></div>'
        			    }
        			});
                	//图片上传插件
               		$('#files1').uploadify({
       	              fileObjName : 'upload',
       	              buttonClass:'uploadBtn',
       	              buttonText:'选择&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
       	              fileTypeDesc:'Image Files',
       	              fileTypeExts:'*.gif; *.jpg; *.png',
       	              fileSizeLimit:'500',
       	           	  width:80,
       	              height:32,
       	              // uploadLimit:1000,
       	              swf:'/plugins/uploadify/uploadify.swf',
       	              uploader:image_server_url+"/upload/uploadifySave.html?nid=goods",
       	              onSelectError: function(file,errorCode,errorMsg){
       	                    if(errorCode==-110){
       	                    	layer.msg('上传的单张图片不能超过500K，请重新上传', 1, -1);
       	                    	return false;
       	                    }
       	                    else if(errorCode==-130){
       	                    	layer.msg('选择的文件类型跟设置的不匹配', 2, -1);
       	                    	return false;
       	                    }
       	              },
       	              onUploadSuccess:function(file,data, response) {
	       	             	if(data!=null){
	    	                	imgUrl = image_server_url+data;
	       	                    $('.filelist').append("<li><a href='"+imgUrl+"' class='fileshow'><img src='"+imgUrl+"' width='110px' height='110px' /></a><i class='iconfont delImgUrl1' title='点击删除图片'>&#xe628;</i></li>");
	       	                }
       	              }
       	        	});
               		//确定并添加到编辑器
               		$(".okBtn").click(function(){
               			var img = "";
               			$(".filelist li a").each(function(){
               				img += $(this).html();
               			});
               			if(img != "" ){
               				//var img = '<img src="'+imgUrl+'" alt="">';
                            tinymceEditor1.insertContent(img);
               			}
               			layer.closeAll();
               		}) 
               		
               		//删除图片
				  	$(".delImgUrl1").live("click",function(){
				    	var _that = $(this);
				     	$.ajax({
				       		url : "/modules/user/score/goods/delPic.html?randomTime=" + (new Date()).getTime(),
				       		data : {pathPic : $(this).prev().attr("src")},
				       		success:function(data){
				          		if(data.result){
				            		_that.parents("li").remove();
				          		}
				       		}
				     	})
				  	})
                }
            });
        },
        statusbar  : false //控制底部状态栏是否显示
    });
    
    $(".fileshow").fancybox();
</script>